package com.woniuxy.repay.task;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.woniuxy.repay.mapper.*;
import org.springframework.cache.annotation.CachePut;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author shichen
 * @create 2021-11-13-19:39
 * @description 每天凌晨刷新缓存
 */
@Component
@EnableAsync
@EnableScheduling
public class RefreshCacheTask {

    private static final Log log = LogFactory.get();

    @Resource
    RepaymentManageMapper repaymentManageMapper;

    @Resource
    RepaymentOverdueMapper repaymentOverdueMapper;

    @Resource
    RepaymentProtectionMapper repaymentProtectionMapper;

    @Resource
    RepaymentReminderMapper repaymentReminderMapper;

    @Resource
    RepaymentRegistrationMapper repaymentRegistrationMapper;


    /**
     * 每天凌晨刷新缓存
     */
    @Async
    @Scheduled(cron = "0 0 1 ? * ? ")
    @CachePut
    public List first(){

        log.debug("刷新缓存: {}",Thread.currentThread().getName());
        return repaymentManageMapper.selectByCondition(null,0,5);
    }

    @Async
    @Scheduled(cron = "0 0 1 ? * ? ")
    @CachePut
    public List second(){

        log.debug("刷新缓存: {}",Thread.currentThread().getName());
        return repaymentOverdueMapper.selectByCondition(null);
    }

    @Async
    @Scheduled(cron = "0 0 1 ? * ? ")
    @CachePut
    public List third(){

        log.debug("刷新缓存: {}",Thread.currentThread().getName());
        return repaymentProtectionMapper.selectByCondition(null);
    }

    @Async
    @Scheduled(cron = "0 0 1 ? * ? ")
    @CachePut
    public List fourth(){

        log.debug("刷新缓存: {}",Thread.currentThread().getName());
        return repaymentRegistrationMapper.selectByCondition(null);
    }
    @Async
    @Scheduled(cron = "0 0 1 ? * ? ")
    @CachePut
    public List fifth(){

        log.debug("刷新缓存: {}",Thread.currentThread().getName());
        return repaymentReminderMapper.selectByCondition(null);
    }
}
